package com.jiasongfan.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jiasongfan.dao.OrderDao;
import com.jiasongfan.entity.*;
import com.jiasongfan.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    OrderDao orderDao;

    @Override
    public TbUser login(TbUser tbUser) {
        return orderDao.login(tbUser);
    }

    @Override
    public PageInfo<TbOrder> list(QueryVO vo, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<TbOrder> pg = new PageInfo<TbOrder>(orderDao.list(vo));
        return pg;
    }

    @Override
    public void add(TbOrder tbOrder) {
        //增加主表
        orderDao. add(tbOrder);
        //增加从表
        List<TbOrderGoods> list = tbOrder.getOrderGoodsList();
        if (list!=null){
            for (TbOrderGoods tbOrderGoods : list) {
                orderDao.addGoods(tbOrderGoods);
            }
        }

    }

    @Override
    public TbOrder selectById(Long oid) {

        return orderDao.selectById(oid);
    }

    @Override
    public void update(TbOrder tbOrder) {
       orderDao. update(tbOrder);
    }

    @Override
    public void register(TbUser tbUser) {
       orderDao. register(tbUser);
    }

    @Override
    public List<Menu> getTree(TbUser user) {
        if (user!=null){
            return orderDao.getTree(user.getMid());
        }
        return null;
    }
}
